<?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
 */

abstract class RealURL2_BaseTest extends sly_BaseTest {
	public function setUp() {
		parent::setUp();
		self::resetConfigValues();
	}

	protected function getDataSetName() {
		return null;
	}

	protected function getAdditionalDataSets() {
		return array(new PHPUnit_Extensions_Database_DataSet_YamlDataSet(__DIR__.'/../datasets/computers.yml'));
	}

	protected function getRequiredComponents() {
		return array('developer_utils', 'global_settings', 'realurl2');
	}

	protected static function setConfigValue($name, $value, $clang) {
		$setting = WV8_Settings::getSetting('realurl2', $name);
		$values  = $setting->getValues(true);

		$values[$clang] = $value;

		$service = new WV8_Service();
		$service->store($setting, $values);
	}

	protected static function resetConfigValues($startArticle = 98) {
		self::setConfigValue('default_fragment', '//cli', 5);
		self::setConfigValue('default_fragment', '//cli/en', 8);

		self::setConfigValue('cleanup', '1', 5);
		self::setConfigValue('cleanup', '0', 8);

		self::setConfigValue('lowercase', '1', 5);
		self::setConfigValue('lowercase', '0', 8);

		sly_Core::cache()->flush('realurl2', true);
		sly_Core::cache()->flush('globalsettings', true);

		sly_Core::config()->set('START_ARTICLE_ID', 98);
		sly_Core::config()->set('NOTFOUND_ARTICLE_ID', 98);
	}

	protected static function rebuildAll() {
		_WV24_Extensions::cacheCleared(array('subject' => true));
	}
}
