Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 17... Línea 17...
17
namespace core_course;
17
namespace core_course;
Línea 18... Línea 18...
18
 
18
 
19
use context_user;
19
use context_user;
20
use context_course;
20
use context_course;
21
use ReflectionMethod;
21
use ReflectionMethod;
22
use cache_definition;
22
use core_cache\definition;
Línea 23... Línea 23...
23
use core_course\cache\course_image;
23
use core_course\cache\course_image;
24
 
24
 
25
/**
25
/**
Línea 29... Línea 29...
29
 * @subpackage course
29
 * @subpackage course
30
 * @author     Dmitrii Metelkin <dmitriim@catalyst-au.net>
30
 * @author     Dmitrii Metelkin <dmitriim@catalyst-au.net>
31
 * @copyright  2021 Catalyst IT
31
 * @copyright  2021 Catalyst IT
32
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 */
33
 */
34
class course_image_cache_test extends \advanced_testcase {
34
final class course_image_cache_test extends \advanced_testcase {
Línea 35... Línea 35...
35
 
35
 
36
    /**
36
    /**
37
     * Initial setup.
37
     * Initial setup.
38
     */
38
     */
Línea 95... Línea 95...
95
    /**
95
    /**
96
     * Test get_image_url_from_overview_files when no summary files in the course.
96
     * Test get_image_url_from_overview_files when no summary files in the course.
97
     */
97
     */
98
    public function test_get_image_url_from_overview_files_return_null_if_no_summary_files_in_the_course(): void {
98
    public function test_get_image_url_from_overview_files_return_null_if_no_summary_files_in_the_course(): void {
99
        $method = new ReflectionMethod(course_image::class, 'get_image_url_from_overview_files');
99
        $method = new ReflectionMethod(course_image::class, 'get_image_url_from_overview_files');
100
        $cache = course_image::get_instance_for_cache(new cache_definition());
100
        $cache = course_image::get_instance_for_cache(new definition());
Línea 101... Línea 101...
101
 
101
 
102
        // Create course without files.
102
        // Create course without files.
103
        $course = $this->getDataGenerator()->create_course();
103
        $course = $this->getDataGenerator()->create_course();
104
        $this->assertNull($method->invokeArgs($cache, [$course]));
104
        $this->assertNull($method->invokeArgs($cache, [$course]));
Línea 107... Línea 107...
107
    /**
107
    /**
108
     * Test get_image_url_from_overview_files when no summary images in the course.
108
     * Test get_image_url_from_overview_files when no summary images in the course.
109
     */
109
     */
110
    public function test_get_image_url_from_overview_files_returns_null_if_no_summary_images_in_the_course(): void {
110
    public function test_get_image_url_from_overview_files_returns_null_if_no_summary_images_in_the_course(): void {
111
        $method = new ReflectionMethod(course_image::class, 'get_image_url_from_overview_files');
111
        $method = new ReflectionMethod(course_image::class, 'get_image_url_from_overview_files');
112
        $cache = course_image::get_instance_for_cache(new cache_definition());
112
        $cache = course_image::get_instance_for_cache(new definition());
Línea 113... Línea 113...
113
 
113
 
114
        // Create course without image files.
114
        // Create course without image files.
115
        $draftid2 = $this->fill_draft_area(['filename2.zip' => 'Test file contents2']);
115
        $draftid2 = $this->fill_draft_area(['filename2.zip' => 'Test file contents2']);
116
        $course2 = $this->getDataGenerator()->create_course(['overviewfiles_filemanager' => $draftid2]);
116
        $course2 = $this->getDataGenerator()->create_course(['overviewfiles_filemanager' => $draftid2]);
Línea 120... Línea 120...
120
    /**
120
    /**
121
     * Test get_image_url_from_overview_files when no summary images in the course.
121
     * Test get_image_url_from_overview_files when no summary images in the course.
122
     */
122
     */
123
    public function test_get_image_url_from_overview_files_returns_url_if_there_is_a_summary_image(): void {
123
    public function test_get_image_url_from_overview_files_returns_url_if_there_is_a_summary_image(): void {
124
        $method = new ReflectionMethod(course_image::class, 'get_image_url_from_overview_files');
124
        $method = new ReflectionMethod(course_image::class, 'get_image_url_from_overview_files');
125
        $cache = course_image::get_instance_for_cache(new cache_definition());
125
        $cache = course_image::get_instance_for_cache(new definition());
Línea 126... Línea 126...
126
 
126
 
-
 
127
        // Create course without one image.
127
        // Create course without one image.
128
        $draftid1 = $this->fill_draft_area([
-
 
129
            'filename1.jpg' => file_get_contents(self::get_fixture_path(__NAMESPACE__, 'image.jpg')),
128
        $draftid1 = $this->fill_draft_area(['filename1.jpg' => file_get_contents(__DIR__ . '/fixtures/image.jpg')]);
130
        ]);
129
        $course1 = $this->getDataGenerator()->create_course(['overviewfiles_filemanager' => $draftid1]);
131
        $course1 = $this->getDataGenerator()->create_course(['overviewfiles_filemanager' => $draftid1]);
130
        $expected = $this->build_expected_course_image_url($course1, 'filename1.jpg');
132
        $expected = $this->build_expected_course_image_url($course1, 'filename1.jpg');
131
        $this->assertEquals($expected, $method->invokeArgs($cache, [$course1]));
133
        $this->assertEquals($expected, $method->invokeArgs($cache, [$course1]));
Línea 132... Línea 134...
132
    }
134
    }
133
 
135
 
134
    /**
136
    /**
135
     * Test get_image_url_from_overview_files when several summary images in the course.
137
     * Test get_image_url_from_overview_files when several summary images in the course.
136
     */
138
     */
137
    public function test_get_image_url_from_overview_files_returns_url_of_the_first_image_if_there_are_many_summary_images(): void {
139
    public function test_get_image_url_from_overview_files_returns_url_of_the_first_image_if_there_are_many_summary_images(): void {
Línea 138... Línea 140...
138
        $method = new ReflectionMethod(course_image::class, 'get_image_url_from_overview_files');
140
        $method = new ReflectionMethod(course_image::class, 'get_image_url_from_overview_files');
139
        $cache = course_image::get_instance_for_cache(new cache_definition());
141
        $cache = course_image::get_instance_for_cache(new definition());
140
 
142
 
141
        // Create course with two image files.
143
        // Create course with two image files.
142
        $draftid1 = $this->fill_draft_area([
144
        $draftid1 = $this->fill_draft_area([
143
            'filename1.jpg' => file_get_contents(__DIR__ . '/fixtures/image.jpg'),
145
            'filename1.jpg' => file_get_contents(self::get_fixture_path(__NAMESPACE__, 'image.jpg')),
Línea 144... Línea 146...
144
            'filename2.jpg' => file_get_contents(__DIR__ . '/fixtures/image.jpg'),
146
            'filename2.jpg' => file_get_contents(self::get_fixture_path(__NAMESPACE__, 'image.jpg')),
145
        ]);
147
        ]);
Línea 152... Línea 154...
152
    /**
154
    /**
153
     * Test get_image_url_from_overview_files when several summary files in the course.
155
     * Test get_image_url_from_overview_files when several summary files in the course.
154
     */
156
     */
155
    public function test_get_image_url_from_overview_files_returns_url_of_the_first_image_if_there_are_many_summary_files(): void {
157
    public function test_get_image_url_from_overview_files_returns_url_of_the_first_image_if_there_are_many_summary_files(): void {
156
        $method = new ReflectionMethod(course_image::class, 'get_image_url_from_overview_files');
158
        $method = new ReflectionMethod(course_image::class, 'get_image_url_from_overview_files');
157
        $cache = course_image::get_instance_for_cache(new cache_definition());
159
        $cache = course_image::get_instance_for_cache(new definition());
Línea 158... Línea 160...
158
 
160
 
159
        // Create course with two image files and one zip file.
161
        // Create course with two image files and one zip file.
160
        $draftid1 = $this->fill_draft_area([
162
        $draftid1 = $this->fill_draft_area([
161
            'filename1.zip' => 'Test file contents2',
163
            'filename1.zip' => 'Test file contents2',
162
            'filename2.jpg' => file_get_contents(__DIR__ . '/fixtures/image.jpg'),
164
            'filename2.jpg' => file_get_contents(self::get_fixture_path(__NAMESPACE__, 'image.jpg')),
163
            'filename3.jpg' => file_get_contents(__DIR__ . '/fixtures/image.jpg'),
165
            'filename3.jpg' => file_get_contents(self::get_fixture_path(__NAMESPACE__, 'image.jpg')),
164
        ]);
166
        ]);
Línea 165... Línea 167...
165
        $course1 = $this->getDataGenerator()->create_course(['overviewfiles_filemanager' => $draftid1]);
167
        $course1 = $this->getDataGenerator()->create_course(['overviewfiles_filemanager' => $draftid1]);
166
 
168