<?php
require_once '../../kernel/includes/setup_inc.php';
use Bitweaver\Articles\BitArticle;

class TestBitArticle extends Test
{
	public $test;
	public $id;
	public $count;

	public function TestBitArticle()
	{
		$this->test = new BitArticle();
		Assert::equalsTrue($this->test != NULL, 'Error during initialisation');
	}

	public function testGetItems()
	{
	$filter = [];
		$list = $this->test->getList($filter);
		$this->count = count($list);
		Assert::equalsTrue(is_array($list));
	}

	public function testStoreItem()
	{
	$newItemHash = [
		"title" => "Test Title",
		"description" => "Test Description",
		"data" => "Test Text",
		"topic_id" => NULL,
		"topic_name" => NULL,
		"size" => NULL,
		"use_image" => NULL,
		"image_name" => NULL,
		"image_type" => NULL,
		"image_size" => NULL,
		"image_x" => NULL,
		"image_y" => NULL,
		"image_data" => "",
		"publish_date" => NULL,
		"expire_date" => NULL,
		"hash" => NULL,
		"type" => NULL,
		"isfloat" => NULL,
	];
		Assert::equalsTrue($this->test->store($newItemHash));
	}

	public function testIsValidItem()
	{
		Assert::equalsTrue($this->test->isValid());
	}

	public function testNullItem()
	{
	$this->id = $this->test->mArticleId;
		$this->test = NULL;
		Assert::equals($this->test, NULL);
	}

	public function testLoadItem()
	{
		$this->test = new BitArticle($this->id);
		Assert::equals($this->test->load(), 37);
	}

	public function testUrlItem()
	{
		Assert::equalsTrue($this->test->getDisplayUrl() != "");
	}

	public function testExpungeItem()
	{
		Assert::equalsTrue($this->test->expunge());
	}

	public function testCountItems()
	{
	$filter = [];
		$count = count($this->test->getList($filter));
		Assert::equals($this->count, $count);
	}

}
