BaseTest.php 1.91 KB
Newer Older
1 2 3 4
<?php

class BaseTest extends PHPUnit_Framework_TestCase
{
5 6
	public function test__qa_js()
	{
Scott committed
7 8
		$this->assertSame("'test'", qa_js('test'));
		$this->assertSame("'test'", qa_js('test', true));
9

10 11
		$this->assertSame(123, qa_js(123));
		$this->assertSame("'123'", qa_js(123, true));
12

13
		$this->assertSame('true', qa_js(true));
Scott committed
14
		$this->assertSame("'true'", qa_js(true, true));
15
	}
16 17 18

	public function test__convert_to_bytes()
	{
19 20
		$this->assertSame(102400, convert_to_bytes('k', 100));
		$this->assertSame(104857600, convert_to_bytes('m', 100));
Scott committed
21
		$this->assertSame(107374182400, convert_to_bytes('g', 100));
22

23 24
		$this->assertSame(102400, convert_to_bytes('K', 100));
		$this->assertSame(104857600, convert_to_bytes('M', 100));
Scott committed
25
		$this->assertSame(107374182400, convert_to_bytes('G', 100));
26

27 28
		$this->assertSame(100, convert_to_bytes('', 100));
		$this->assertSame(1048576, convert_to_bytes('k', 1024));
29 30
	}

Scott committed
31 32
	public function test__qa_q_request()
	{
Scott committed
33 34
		// set options cache to bypass database
		global $qa_options_cache, $qa_blockwordspreg_set;
Scott committed
35 36 37 38

		$title1 = 'How much wood would a woodchuck chuck if a woodchuck could chuck wood?';
		$title2 = 'Țĥé qũīçĶ ßřǭŴƞ Ƒöŧ ǰÙƢƥş ØƯĘŕ ƬĦȨ ĿÆƶȳ Ƌơǥ';

Scott committed
39 40
		$qa_options_cache['block_bad_words'] = '';
		$qa_blockwordspreg_set = false;
Scott committed
41 42 43 44 45 46
		$qa_options_cache['q_urls_title_length'] = 50;
		$qa_options_cache['q_urls_remove_accents'] = false;
		$expected1 = '1234/much-wood-would-woodchuck-chuck-woodchuck-could-chuck-wood';

		$this->assertSame($expected1, qa_q_request(1234, $title1));

Scott committed
47 48
		$qa_options_cache['block_bad_words'] = 'chuck';
		$qa_blockwordspreg_set = false;
Scott committed
49
		$qa_options_cache['q_urls_remove_accents'] = true;
Scott committed
50
		$expected2 = '5678/how-much-wood-would-a-woodchuck-if-a-woodchuck-could-wood';
Scott committed
51 52
		$expected3 = '9000/the-quick-ssrown-fot-juoips-ouer-the-laezy-dog';

Scott committed
53
		$this->assertSame($expected2, qa_q_request(5678, $title1));
Scott committed
54 55
		$this->assertSame($expected3, qa_q_request(9000, $title2));
	}
56
}