Merge branch 'master' of https://github.com/yiisoft/yii2 into schema-cache-fixes

This commit is contained in:
brandonkelly
2017-04-27 10:35:30 -07:00
48 changed files with 380 additions and 97 deletions

View File

@ -225,4 +225,36 @@ class SortTest extends TestCase
$this->assertEquals('<a class="asc" href="/index.php?r=site%2Findex&amp;sort=-age%2C-name" data-sort="-age,-name">Age</a>', $sort->link('age'));
}
public function testParseSortParam()
{
$sort = new CustomSort([
'attributes' => [
'age',
'name'
],
'params' => [
'sort' => [
['field' => 'age', 'dir' => 'asc'],
['field' => 'name', 'dir' => 'desc']
]
],
'enableMultiSort' => true
]);
$this->assertEquals(SORT_ASC, $sort->getAttributeOrder('age'));
$this->assertEquals(SORT_DESC, $sort->getAttributeOrder('name'));
}
}
class CustomSort extends Sort
{
protected function parseSortParam($params)
{
$attributes = [];
foreach ($params as $item) {
$attributes[] = ($item['dir'] == 'desc') ? '-' . $item['field'] : $item['field'];
}
return $attributes;
}
}

View File

@ -32,4 +32,16 @@ class SqlDataProviderTest extends DatabaseTestCase
]);
$this->assertEquals(3, $dataProvider->getTotalCount());
}
public function testTotalCountWithParams()
{
$dataProvider = new SqlDataProvider([
'sql' => 'select * from `customer` where id > :minimum',
'params' => [
':minimum' => -1
],
'db' => $this->getConnection(),
]);
$this->assertEquals(3, $dataProvider->getTotalCount());
}
}

View File

@ -112,7 +112,6 @@ class InstanceTest extends TestCase
$this->expectExceptionMessage('"db" refers to a yii\db\Connection component. yii\base\Widget is expected.');
Instance::ensure('db', 'yii\base\Widget', $container);
Instance::ensure(['class' => 'yii\db\Connection', 'dsn' => 'test'], 'yii\base\Widget', $container);
}
public function testExceptionInvalidDataType()
@ -191,4 +190,12 @@ PHP
Instance::__set_state([]);
}
public function testExceptionInvalidDataTypeInArray()
{
$this->setExpectedException('yii\base\InvalidConfigException', 'Invalid data type: yii\db\Connection. yii\base\Widget is expected.');
Instance::ensure([
'class' => Connection::className(),
], 'yii\base\Widget');
}
}

View File

@ -5,7 +5,6 @@ namespace yiiunit\framework\filters;
use Yii;
use yii\base\Action;
use yii\filters\AccessRule;
use yii\filters\HttpCache;
use yii\web\Controller;
use yii\web\Request;
use yii\web\User;
@ -21,8 +20,8 @@ class AccessRuleTest extends \yiiunit\TestCase
{
parent::setUp();
$_SERVER['SCRIPT_FILENAME'] = "/index.php";
$_SERVER['SCRIPT_NAME'] = "/index.php";
$_SERVER['SCRIPT_FILENAME'] = '/index.php';
$_SERVER['SCRIPT_NAME'] = '/index.php';
$this->mockWebApplication();
}
@ -42,7 +41,7 @@ class AccessRuleTest extends \yiiunit\TestCase
}
/**
* @param string optional user id
* @param string $userid optional user id
* @return User
*/
protected function mockUser($userid = null)
@ -292,6 +291,14 @@ class AccessRuleTest extends \yiiunit\TestCase
$this->assertNull($rule->allows($action, $user, $request));
$rule->allow = false;
$this->assertNull($rule->allows($action, $user, $request));
// undefined IP
$_SERVER['REMOTE_ADDR'] = null;
$rule->ips = ['192.168.*'];
$rule->allow = true;
$this->assertNull($rule->allows($action, $user, $request));
$rule->allow = false;
$this->assertNull($rule->allows($action, $user, $request));
}
public function testMatchIPWildcard()

View File

@ -44,7 +44,9 @@ class ArrayHelperTest extends TestCase
protected function setUp()
{
parent::setUp();
$this->mockApplication();
// destroy application, Helper must work without Yii::$app
$this->destroyApplication();
}
public function testToArray()
@ -267,6 +269,7 @@ class ArrayHelperTest extends TestCase
$sort = new Sort([
'attributes' => ['name', 'age'],
'defaultOrder' => ['name' => SORT_ASC],
'params' => [],
]);
$orders = $sort->getOrders();
@ -284,6 +287,7 @@ class ArrayHelperTest extends TestCase
$sort = new Sort([
'attributes' => ['name', 'age'],
'defaultOrder' => ['name' => SORT_ASC, 'age' => SORT_DESC],
'params' => [],
]);
$orders = $sort->getOrders();

View File

@ -12,6 +12,14 @@ use yiiunit\TestCase;
*/
class ConsoleTest extends TestCase
{
protected function setUp()
{
parent::setUp();
// destroy application, Helper must work without Yii::$app
$this->destroyApplication();
}
public function testStripAnsiFormat()
{
ob_start();

View File

@ -33,8 +33,14 @@ class FileHelperTest extends TestCase
*/
$this->markTestInComplete('Unit tests runtime directory should be local!');
}
parent::setUp();
// destroy application, Helper must work without Yii::$app
$this->destroyApplication();
}
public function tearDown()
{
$this->removeDir($this->testFilePath);

View File

@ -10,6 +10,14 @@ use yiiunit\TestCase;
*/
class InflectorTest extends TestCase
{
protected function setUp()
{
parent::setUp();
// destroy application, Helper must work without Yii::$app
$this->destroyApplication();
}
public function testPluralize()
{
$testData = [

View File

@ -14,6 +14,14 @@ use yiiunit\framework\web\Post;
*/
class JsonTest extends TestCase
{
protected function setUp()
{
parent::setUp();
// destroy application, Helper must work without Yii::$app
$this->destroyApplication();
}
public function testEncode()
{
// basic data encoding

View File

@ -12,6 +12,14 @@ use yii\helpers\Markdown;
*/
class MarkdownTest extends TestCase
{
protected function setUp()
{
parent::setUp();
// destroy application, Helper must work without Yii::$app
$this->destroyApplication();
}
public function testOriginalFlavor()
{
$text = <<<TEXT

View File

@ -10,6 +10,14 @@ use yiiunit\TestCase;
*/
class VarDumperTest extends TestCase
{
protected function setUp()
{
parent::setUp();
// destroy application, Helper must work without Yii::$app
$this->destroyApplication();
}
public function testDumpIncompleteObject()
{
$serializedObj = 'O:16:"nonExistingClass":0:{}';

View File

@ -14,7 +14,9 @@ class BooleanValidatorTest extends TestCase
protected function setUp()
{
parent::setUp();
$this->mockApplication();
// destroy application, Validator must work without Yii::$app
$this->destroyApplication();
}
public function testValidateValue()

View File

@ -14,7 +14,9 @@ class CompareValidatorTest extends TestCase
protected function setUp()
{
parent::setUp();
$this->mockApplication();
// destroy application, Validator must work without Yii::$app
$this->destroyApplication();
}
public function testValidateValueException()

View File

@ -13,7 +13,9 @@ class DefaultValueValidatorTest extends TestCase
protected function setUp()
{
parent::setUp();
$this->mockApplication();
// destroy application, Validator must work without Yii::$app
$this->destroyApplication();
}
public function testValidateAttribute()

View File

@ -14,7 +14,9 @@ class EachValidatorTest extends TestCase
protected function setUp()
{
parent::setUp();
$this->mockApplication();
// destroy application, Validator must work without Yii::$app
$this->destroyApplication();
}
public function testArrayFormat()

View File

@ -13,7 +13,9 @@ class EmailValidatorTest extends TestCase
protected function setUp()
{
parent::setUp();
$this->mockApplication();
// destroy application, Validator must work without Yii::$app
$this->destroyApplication();
}
public function testValidateValue()

View File

@ -14,10 +14,12 @@ use yiiunit\framework\db\DatabaseTestCase;
abstract class ExistValidatorTest extends DatabaseTestCase
{
public function setUp()
protected function setUp()
{
parent::setUp();
$this->mockApplication();
// destroy application, Validator must work without Yii::$app
$this->destroyApplication();
ActiveRecord::$db = $this->getConnection();
}

View File

@ -14,8 +14,9 @@ use yiiunit\TestCase;
*/
class FileValidatorTest extends TestCase
{
public function setUp()
protected function setUp()
{
parent::setUp();
$this->mockApplication();
}

View File

@ -14,7 +14,8 @@ class FilterValidatorTest extends TestCase
protected function setUp()
{
parent::setUp();
$this->mockApplication();
// destroy application, Validator must work without Yii::$app
$this->destroyApplication();
}
public function testAssureExceptionOnInit()

View File

@ -14,7 +14,8 @@ class IpValidatorTest extends TestCase
protected function setUp()
{
parent::setUp();
$this->mockApplication();
// destroy application, Validator must work without Yii::$app
$this->destroyApplication();
}
public function testInitException()

View File

@ -46,8 +46,11 @@ class NumberValidatorTest extends TestCase
protected function setUp()
{
parent::setUp();
$this->mockApplication();
$this->oldLocale = setlocale(LC_NUMERIC, 0);
// destroy application, Validator must work without Yii::$app
$this->destroyApplication();
}
public function testEnsureMessageOnInit()

View File

@ -14,7 +14,9 @@ class RangeValidatorTest extends TestCase
protected function setUp()
{
parent::setUp();
$this->mockApplication();
// destroy application, Validator must work without Yii::$app
$this->destroyApplication();
}
public function testInitException()

View File

@ -14,7 +14,9 @@ class RegularExpressionValidatorTest extends TestCase
protected function setUp()
{
parent::setUp();
$this->mockApplication();
// destroy application, Validator must work without Yii::$app
$this->destroyApplication();
}
public function testValidateValue()

View File

@ -13,7 +13,9 @@ class RequiredValidatorTest extends TestCase
protected function setUp()
{
parent::setUp();
$this->mockApplication();
// destroy application, Validator must work without Yii::$app
$this->destroyApplication();
}
public function testValidateValueWithDefaults()

View File

@ -16,11 +16,13 @@ use yiiunit\framework\db\DatabaseTestCase;
abstract class UniqueValidatorTest extends DatabaseTestCase
{
public function setUp()
protected function setUp()
{
parent::setUp();
$this->mockApplication();
ActiveRecord::$db = $this->getConnection();
// destroy application, Validator must work without Yii::$app
$this->destroyApplication();
}
public function testAssureMessageSetOnInit()

View File

@ -14,7 +14,9 @@ class UrlValidatorTest extends TestCase
protected function setUp()
{
parent::setUp();
$this->mockApplication();
// destroy application, Validator must work without Yii::$app
$this->destroyApplication();
}
public function testValidateValue()

View File

@ -17,7 +17,9 @@ class ValidatorTest extends TestCase
protected function setUp()
{
parent::setUp();
$this->mockApplication();
// destroy application, Validator must work without Yii::$app
$this->destroyApplication();
}
protected function getTestModel($additionalAttributes = [])
@ -240,17 +242,27 @@ class ValidatorTest extends TestCase
$this->assertEquals('attr_msg_val::abc::param_value', $errors[0]);
}
public function testGetAttributeNames()
{
$validator = new TestValidator();
$validator->attributes = ['id', 'name', '!email'];
$this->assertEquals(['id', 'name', 'email'], $validator->getAttributeNames());
}
/**
* @depends testGetAttributeNames
*/
public function testGetActiveValidatorsForSafeAttributes()
{
$model = $this->getTestModel();
$validators = $model->getActiveValidators('safe_attr');
$is_found = false;
$isFound = false;
foreach ($validators as $v) {
if ($v instanceof NumberValidator) {
$is_found = true;
$isFound = true;
break;
}
}
$this->assertTrue($is_found);
$this->assertTrue($isFound);
}
}

View File

@ -69,6 +69,16 @@ class XmlResponseFormatterTest extends FormatterTest
'c' => [2, '<>'],
false,
], "<response><a>1</a><b>abc</b><c><item>2</item><item>&lt;&gt;</item></c><item>false</item></response>\n"],
// Checks if empty keys and keys not valid in XML are processed.
// See https://github.com/yiisoft/yii2/pull/10346/
[[
'' => 1,
'2015-06-18' => '2015-06-18',
'b:c' => 'b:c',
'a b c' => 'a b c',
'äøñ' => 'äøñ'
], "<response><item>1</item><item>2015-06-18</item><item>b:c</item><item>a b c</item><äøñ>äøñ</äøñ></response>\n"],
]);
}