Example #1
0
	/**
	 * Tests inserting a new Product category - makes sure all fields are properly persisted
	 *
	 * @return void
	 */
	public function testInsertCategory_ValidData()
	{
		$shopModel = getModel('shop');
		$repository = $shopModel->getCategoryRepository();

        // Create new Product category object
        $category = new Category();
        $category->module_srl = 2;
        $category->title = "Product category 1";

		try
		{
			// Try to insert the new Category
			$category_srl = $repository->insertCategory($category);

			// Check that a srl was returned
			$this->assertNotNull($category_srl);

			// Read the newly created object from the database, to compare it with the source object
			$output = Database::executeQuery("SELECT * FROM xe_shop_categories WHERE category_srl = $category_srl");
			$this->assertEquals(1, count($output));

			$new_category = $output[0];
			$this->assertEquals($category->module_srl, $new_category->module_srl);
			$this->assertEquals($category->title, $new_category->title);
			$this->assertNotNull($new_category->regdate);
			$this->assertNotNull($new_category->last_update);

			// Delete product we just added after test is finished
			Database::executeNonQuery("DELETE FROM xe_shop_categories WHERE category_srl = $category_srl");
		} catch(Exception $e)
		{
			$this->fail($e->getMessage());
		}
	}