/** * Tests the validate() method in Category_Model * * @test * @dataProvider providerValidate * @param array $valid Valid data for the test * @param array $invalid Invalid data for the test * @param array $save Saves the record when validation succeeds */ public function testValidate($valid, $invalid, $save) { // Model instance for the test $category = new Category_Model(); // Valid data test $this->assertEquals(TRUE, $category->validate($valid, $save)); // Invalid data test $this->assertEquals(FALSE, $category->validate($invalid, $save)); }
/** * Tests the validate() method in Category_Model * * @test * @dataProvider providerValidate * @param array $valid Valid data for the test * @param array $invalid Invalid data for the test * @param array $save Saves the record when validation succeeds */ public function testValidate($valid, $invalid, $invalid2, $specialsub, $save) { // Model instance for the test on a new category $category = new Category_Model(); // Model instance for the test on an existing special category $special_sub = new Category_Model(testutils::get_random_id('category', 'WHERE category_trusted = 1')); // Valid data test $this->assertEquals(TRUE, $category->validate($valid, $save)); // Invalid data test 1 $this->assertEquals(FALSE, $category->validate($invalid, $save)); // Invalid data test 2 $this->assertEquals(FALSE, $category->validate($invalid2, $save)); // Invalid data test 3 $this->assertEquals(FALSE, $special_sub->validate($specialsub, $save)); }
/** * Save newly added dynamic categories */ public function save_category() { $this->auto_render = FALSE; $this->template = ""; // Check, has the form been submitted, if so, setup validation if ($_POST) { // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things // HT: New code for category save with parent $post = arr::extract($_POST, 'parent_id', 'category_title', 'category_description', 'category_color'); // Category instance for the operation $category = new Category_Model(); if ($category->validate($post)) { $category->save(); $form_saved = TRUE; echo json_encode(array("status" => "saved", "id" => $category->id)); } else { echo json_encode(array("status" => "error")); } } else { echo json_encode(array("status" => "error")); } }