<?php
/*
 * Copyright (c) 2012, webvariants GbR, http://www.webvariants.de
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 */

class RealURL2_UtilDatabaseTest extends RealURL2_BaseTest {
	/**
	 * @dataProvider getTreeProvider
	 */
	public function testGetTree($id, $expected) {
		$this->assertEquals($expected, WV24_Util::getTree($id));
	}

	public function getTreeProvider() {
		return array(
			array(1,    array(1 => '|48|', 99 => '|48|1|', 100 => '|48|1|')),
			array(2,    array(2 => '|48|', 15 => '|48|2|', 16 => '|48|2|', 18 => '|48|2|', 101 => '|48|2|', 102 => '|48|2|15|'))
		);
	}

	public function testHasStartArticle() {
		$this->assertTrue(WV24_Util::hasSiteStartArticle());
	}

	public function testGetFragment() {
		$db = sly_DB_Persistence::getInstance();
		$db->update('article', array('wv24_fragment' => '/foo', 'wv24_skip' => '1'), array('id' => 99, 'clang' => 5));

		$articleA = sly_Util_Article::findById(90, 5);

		$this->assertEquals('',    WV24_Util::getFragment($articleA));
		$this->assertEquals(false, WV24_Util::isSkipped($articleA));

		$this->assertEquals('',    $articleA->getFragment());
		$this->assertEquals(false, $articleA->isSkipped());

		$articleA = sly_Util_Article::findById(99, 5);

		$this->assertEquals('/foo', WV24_Util::getFragment($articleA));
		$this->assertEquals(true,   WV24_Util::isSkipped($articleA));

		$this->assertEquals('/foo', $articleA->getFragment());
		$this->assertEquals(true,   $articleA->isSkipped());

		$articleA = sly_Util_Article::findById(99, 8);

		$this->assertEquals('',    WV24_Util::getFragment($articleA));
		$this->assertEquals(false, WV24_Util::isSkipped($articleA));

		$this->assertEquals('',    $articleA->getFragment());
		$this->assertEquals(false, $articleA->isSkipped());
	}
}
