public function test_get_course_categories() { $this->resetAfterTest(); $generator = $this->getDataGenerator(); $cat1 = $generator->create_category((object) ['name' => 'cat1']); $cat2 = $generator->create_category((object) ['name' => 'cat2', 'parent' => $cat1->id]); $cat3 = $generator->create_category((object) ['name' => 'cat3', 'parent' => $cat2->id]); $course1 = $generator->create_course((object) ['category' => $cat3->id, 'visible' => 0, 'oldvisible' => 0]); $categories = local::get_course_categories($course1); // First item in array should be immediate parent - $cat3. $expected = $cat3; $actual = reset($categories); $this->assertEquals($expected->id, $actual->id); // Second item in array should be parent of immediate parent - $cat2. $expected = $cat2; $actual = array_slice($categories, 1, 1); $actual = reset($actual); $this->assertEquals($expected->id, $actual->id); // Final item in array should be a root category - $cat1. $actual = end($categories); $this->assertEmpty($actual->parent); $expected = $cat1; $this->assertEquals($expected->id, $actual->id); }