/** * Very basic test for create/move/update/delete actions, without any itemtype movements. */ public function test_tag_coll_basic() { global $DB; // Make sure there is one and only one tag coll that is marked as default. $tagcolls = core_tag_collection::get_collections(); $this->assertEquals(1, count($DB->get_records('tag_coll', array('isdefault' => 1)))); $defaulttagcoll = core_tag_collection::get_default(); // Create a new tag coll to store user tags and something else. $data = (object) array('name' => 'new tag coll'); $tagcollid1 = core_tag_collection::create($data)->id; $tagcolls = core_tag_collection::get_collections(); $this->assertEquals('new tag coll', $tagcolls[$tagcollid1]->name); // Create a new tag coll to store post tags. $data = (object) array('name' => 'posts'); $tagcollid2 = core_tag_collection::create($data)->id; $tagcolls = core_tag_collection::get_collections(); $this->assertEquals('posts', $tagcolls[$tagcollid2]->name); $this->assertEquals($tagcolls[$tagcollid1]->sortorder + 1, $tagcolls[$tagcollid2]->sortorder); // Illegal tag colls sortorder changing. $this->assertFalse(core_tag_collection::change_sortorder($tagcolls[$defaulttagcoll], 1)); $this->assertFalse(core_tag_collection::change_sortorder($tagcolls[$defaulttagcoll], -1)); $this->assertFalse(core_tag_collection::change_sortorder($tagcolls[$tagcollid2], 1)); // Move the very last tag coll one position up. $this->assertTrue(core_tag_collection::change_sortorder($tagcolls[$tagcollid2], -1)); $tagcolls = core_tag_collection::get_collections(); $this->assertEquals($tagcolls[$tagcollid2]->sortorder + 1, $tagcolls[$tagcollid1]->sortorder); // Move the second last tag coll one position down. $this->assertTrue(core_tag_collection::change_sortorder($tagcolls[$tagcollid2], 1)); $tagcolls = core_tag_collection::get_collections(); $this->assertEquals($tagcolls[$tagcollid1]->sortorder + 1, $tagcolls[$tagcollid2]->sortorder); // Edit tag coll. $this->assertTrue(core_tag_collection::update($tagcolls[$tagcollid2], (object) array('name' => 'posts2'))); $tagcolls = core_tag_collection::get_collections(); $this->assertEquals('posts2', $tagcolls[$tagcollid2]->name); // Delete tag coll. $count = $DB->count_records('tag_coll'); $this->assertFalse(core_tag_collection::delete($tagcolls[$defaulttagcoll])); $this->assertTrue(core_tag_collection::delete($tagcolls[$tagcollid1])); $this->assertEquals($count - 1, $DB->count_records('tag_coll')); }
redirect(new moodle_url($manageurl, array('notice' => 'changessaved'))); } redirect($manageurl); break; case 'collmoveup': if ($tagcoll) { require_sesskey(); core_tag_collection::change_sortorder($tagcoll, -1); redirect(new moodle_url($manageurl, array('notice' => 'changessaved'))); } redirect($manageurl); break; case 'collmovedown': if ($tagcoll) { require_sesskey(); core_tag_collection::change_sortorder($tagcoll, 1); redirect(new moodle_url($manageurl, array('notice' => 'changessaved'))); } redirect($manageurl); break; case 'areaenable': case 'areadisable': if ($tagarea) { require_sesskey(); $data = array('enabled' => $action === 'areaenable' ? 1 : 0); core_tag_area::update($tagarea, $data); redirect(new moodle_url($manageurl, array('notice' => 'changessaved'))); } redirect($manageurl); break; case 'areasetcoll':