From 2a19b3caa075ddd1f4793bf9c5c2117f67a90d2a Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Sat, 10 Jan 2015 18:36:47 +0100 Subject: [PATCH] fixed whitespace in tests --- tests/unit/framework/base/ExposedSecurity.php | 2 +- .../controllers/CacheControllerTest.php | 8 +- .../MigrateControllerTestTrait.php | 2 +- .../controllers/POMessageControllerTest.php | 2 +- .../StdOutBufferControllerTrait.php | 2 +- .../framework/helpers/StringHelperTest.php | 8 +- tests/unit/framework/i18n/I18NTest.php | 2 +- .../unit/framework/test/ArrayFixtureTest.php | 2 +- .../framework/widgets/ActiveFieldTest.php | 140 +++++++++--------- .../framework/widgets/BreadcrumbsTest.php | 78 +++++----- 10 files changed, 123 insertions(+), 123 deletions(-) diff --git a/tests/unit/framework/base/ExposedSecurity.php b/tests/unit/framework/base/ExposedSecurity.php index 790905774b..431e123924 100644 --- a/tests/unit/framework/base/ExposedSecurity.php +++ b/tests/unit/framework/base/ExposedSecurity.php @@ -24,4 +24,4 @@ class ExposedSecurity extends Security { return parent::pbkdf2($algo, $password, $salt, $iterations, $length); } -} \ No newline at end of file +} \ No newline at end of file diff --git a/tests/unit/framework/console/controllers/CacheControllerTest.php b/tests/unit/framework/console/controllers/CacheControllerTest.php index 714c6f150e..73e00d10d3 100644 --- a/tests/unit/framework/console/controllers/CacheControllerTest.php +++ b/tests/unit/framework/console/controllers/CacheControllerTest.php @@ -30,7 +30,7 @@ class CacheControllerTest extends TestCase 'class' => 'yiiunit\framework\console\controllers\SilencedCacheController', 'interactive' => false, ],[null, null]); //id and module are null - + $databases = self::getParam('databases'); $config = $databases[$this->driverName]; $pdoDriver = 'pdo_' . $this->driverName; @@ -38,7 +38,7 @@ class CacheControllerTest extends TestCase if (!extension_loaded('pdo') || !extension_loaded($pdoDriver)) { $this->markTestSkipped('pdo and ' . $pdoDriver . ' extensions are required.'); } - + $this->mockApplication([ 'components' => [ @@ -55,7 +55,7 @@ class CacheControllerTest extends TestCase ], ], ]); - + if(isset($config['fixture'])) { Yii::$app->db->open(); $lines = explode(';', file_get_contents($config['fixture'])); @@ -79,7 +79,7 @@ class CacheControllerTest extends TestCase $this->assertFalse(Yii::$app->firstCache->get('secondKey'),'first cache data should be flushed'); $this->assertEquals('thirdValue', Yii::$app->secondCache->get('thirdKey'), 'second cache data should not be flushed'); } - + public function testClearSchema() { $schema = Yii::$app->db->schema; diff --git a/tests/unit/framework/console/controllers/MigrateControllerTestTrait.php b/tests/unit/framework/console/controllers/MigrateControllerTestTrait.php index 8d5f82f9c1..ec8315bffa 100644 --- a/tests/unit/framework/console/controllers/MigrateControllerTestTrait.php +++ b/tests/unit/framework/console/controllers/MigrateControllerTestTrait.php @@ -255,4 +255,4 @@ CODE; $this->assertMigrationHistory(['base', 'test1']); } -} \ No newline at end of file +} \ No newline at end of file diff --git a/tests/unit/framework/console/controllers/POMessageControllerTest.php b/tests/unit/framework/console/controllers/POMessageControllerTest.php index 6209a4c611..a02a13a68b 100644 --- a/tests/unit/framework/console/controllers/POMessageControllerTest.php +++ b/tests/unit/framework/console/controllers/POMessageControllerTest.php @@ -82,4 +82,4 @@ class POMessageControllerTest extends BaseMessageControllerTest $gettext = new GettextPoFile(); return $gettext->load($messageFilePath, $category); } -} \ No newline at end of file +} \ No newline at end of file diff --git a/tests/unit/framework/console/controllers/StdOutBufferControllerTrait.php b/tests/unit/framework/console/controllers/StdOutBufferControllerTrait.php index 1b71730c5e..f5a5d45607 100644 --- a/tests/unit/framework/console/controllers/StdOutBufferControllerTrait.php +++ b/tests/unit/framework/console/controllers/StdOutBufferControllerTrait.php @@ -24,4 +24,4 @@ trait StdOutBufferControllerTrait $this->stdOutBuffer = ''; return $result; } -} \ No newline at end of file +} \ No newline at end of file diff --git a/tests/unit/framework/helpers/StringHelperTest.php b/tests/unit/framework/helpers/StringHelperTest.php index 0d95dc9a84..bed726f5ac 100644 --- a/tests/unit/framework/helpers/StringHelperTest.php +++ b/tests/unit/framework/helpers/StringHelperTest.php @@ -99,25 +99,25 @@ class StringHelperTest extends TestCase $this->assertEquals('foo', StringHelper::basename('/bar/foo/')); $this->assertEquals('foo', StringHelper::basename('\\bar\\foo\\')); } - + public function testTruncate() { $this->assertEquals('привет, я multibyte...', StringHelper::truncate('привет, я multibyte строка!', 20)); $this->assertEquals('Не трогаем строку', StringHelper::truncate('Не трогаем строку', 20)); $this->assertEquals('исполь!!!', StringHelper::truncate('используем восклицательные знаки', 6, '!!!')); - + // With Html $this->assertEquals('This is a test ...', StringHelper::truncate('This is a test sentance', 14, '...', null, true)); $this->assertEquals('This is a test ...', StringHelper::truncate('This is a test sentance', 14, '...', null, true)); } - + public function testTruncateWords() { $this->assertEquals('это тестовая multibyte строка', StringHelper::truncateWords('это тестовая multibyte строка', 5)); $this->assertEquals('это тестовая multibyte...', StringHelper::truncateWords('это тестовая multibyte строка', 3)); $this->assertEquals('это тестовая multibyte!!!', StringHelper::truncateWords('это тестовая multibyte строка', 3, '!!!')); $this->assertEquals('это строка с неожиданными...', StringHelper::truncateWords('это строка с неожиданными пробелами', 4)); - + // With Html $this->assertEquals('This is a test...', StringHelper::truncateWords('This is a test sentance', 4, '...', true)); $this->assertEquals('This is a test...', StringHelper::truncateWords('This is a test sentance', 4, '...', true)); diff --git a/tests/unit/framework/i18n/I18NTest.php b/tests/unit/framework/i18n/I18NTest.php index 61a0ae28c1..a3ab856f1d 100644 --- a/tests/unit/framework/i18n/I18NTest.php +++ b/tests/unit/framework/i18n/I18NTest.php @@ -53,7 +53,7 @@ class I18NTest extends TestCase // fallback to just langauge code with present exact match $this->assertEquals('Hallo Welt!', $this->i18n->translate('test', 'Hello world!', [], 'de-DE')); } - + public function testDefaultSource() { $i18n = new I18N([ diff --git a/tests/unit/framework/test/ArrayFixtureTest.php b/tests/unit/framework/test/ArrayFixtureTest.php index ec53e4ba31..994dd9fcb3 100644 --- a/tests/unit/framework/test/ArrayFixtureTest.php +++ b/tests/unit/framework/test/ArrayFixtureTest.php @@ -15,7 +15,7 @@ class ArrayFixtureTest extends TestCase { /** - * @var \yii\test\ArrayFixture + * @var \yii\test\ArrayFixture */ private $_fixture; diff --git a/tests/unit/framework/widgets/ActiveFieldTest.php b/tests/unit/framework/widgets/ActiveFieldTest.php index 26490f3eb4..0773f7daa7 100644 --- a/tests/unit/framework/widgets/ActiveFieldTest.php +++ b/tests/unit/framework/widgets/ActiveFieldTest.php @@ -11,7 +11,7 @@ use yii\web\AssetManager; /** * @author Nelson J Morais - * + * * @group widgets */ class ActiveFieldTest extends \yiiunit\TestCase @@ -20,30 +20,30 @@ class ActiveFieldTest extends \yiiunit\TestCase private $helperModel; private $helperForm; private $attributeName = 'attributeName'; - + public function setUp() { // dirty way to have Request object not throwing exception when running testHomeLinkNull() $_SERVER['SCRIPT_FILENAME'] = "index.php"; $_SERVER['SCRIPT_NAME'] = "index.php"; - + $this->mockWebApplication(); - + Yii::setAlias('@testWeb', '/'); Yii::setAlias('@testWebRoot', '@yiiunit/data/web'); - + $this->helperModel = new DynamicModel(['attributeName']); ob_start(); $this->helperForm = new ActiveForm(['action' => '/something']); ob_end_clean(); - + $this->activeField = new ActiveFieldExtend(true); $this->activeField->form = $this->helperForm; $this->activeField->form->setView($this->getView()); $this->activeField->model = $this->helperModel; $this->activeField->attribute = $this->attributeName; } - + public function testRenderNoContent() { $expectedValue = << EOD; - + $actualValue = $this->activeField->render(); $this->assertEquals($expectedValue, $actualValue); } - + /** * @todo discuss|review Expected HTML shouldn't be wrapped only by the $content? */ @@ -80,101 +80,101 @@ EOD; EOD; - + $actualValue = $this->activeField->render($content); $this->assertEquals($expectedValue, $actualValue); } - + public function testBeginHasErros() { $this->helperModel->addError($this->attributeName, "Error Message"); - + $expectedValue = '
'; $actualValue = $this->activeField->begin(); - + $this->assertEquals($expectedValue, $actualValue); } - + public function testBeginAttributeIsRequered() { $this->helperModel->addRule($this->attributeName, 'required'); - + $expectedValue = '
'; $actualValue = $this->activeField->begin(); - - $this->assertEquals($expectedValue, $actualValue); + + $this->assertEquals($expectedValue, $actualValue); } - + public function testBeginHasErrorAndRequired() { $this->helperModel->addError($this->attributeName, "Error Message"); $this->helperModel->addRule($this->attributeName, 'required'); - + $expectedValue = '
'; $actualValue = $this->activeField->begin(); - + $this->assertEquals($expectedValue, $actualValue); } - + public function testEnd() { $expectedValue = '
'; $actualValue = $this->activeField->end(); - + $this->assertEquals($expectedValue, $actualValue); - + // other tag $expectedValue = ""; $this->activeField->options['tag'] = 'article'; $actualValue = $this->activeField->end(); - + $this->assertTrue($actualValue === $expectedValue); } - + public function testLabel() { $expectedValue = ''; $this->activeField->label(); - + $this->assertEquals($expectedValue, $this->activeField->parts['{label}']); - + // label = false $expectedValue = ''; $this->activeField->label(false); - + $this->assertEquals($expectedValue, $this->activeField->parts['{label}']); - + // $label = 'Label Name' $label = 'Label Name'; $expectedValue = <<{$label} EOT; $this->activeField->label($label); - + $this->assertEquals($expectedValue, $this->activeField->parts['{label}']); } - + public function testError() { $expectedValue = ''; $this->activeField->label(); - + $this->assertEquals($expectedValue, $this->activeField->parts['{label}']); - + // label = false $expectedValue = ''; $this->activeField->label(false); - + $this->assertEquals($expectedValue, $this->activeField->parts['{label}']); - + // $label = 'Label Name' $label = 'Label Name'; $expectedValue = <<{$label} EOT; $this->activeField->label($label); - + $this->assertEquals($expectedValue, $this->activeField->parts['{label}']); } @@ -182,28 +182,28 @@ EOT; { $expectedValue = '
Hint Content
'; $this->activeField->hint('Hint Content'); - + $this->assertEquals($expectedValue, $this->activeField->parts['{hint}']); } - + public function testInput() { $expectedValue = << EOD; $this->activeField->input("password"); - - $this->assertEquals($expectedValue, $this->activeField->parts['{input}']); - + + $this->assertEquals($expectedValue, $this->activeField->parts['{input}']); + // with options $expectedValue = << EOD; $this->activeField->input("password", ['weird' => 'value']); - - $this->assertEquals($expectedValue, $this->activeField->parts['{input}']); + + $this->assertEquals($expectedValue, $this->activeField->parts['{input}']); } - + public function testTextInput() { $expectedValue = <<activeField->textInput(); $this->assertEquals($expectedValue, $this->activeField->parts['{input}']); } - + public function testHiddenInput() { $expectedValue = <<activeField->hiddenInput(); $this->assertEquals($expectedValue, $this->activeField->parts['{input}']); } - + public function testListBox() { $expectedValue = <<activeField->listBox(["1" => "Item One", "2" => "Item 2"]); $this->assertEquals($expectedValue, $this->activeField->parts['{input}']); } - - - + + + public function testGetClientOptionsReturnEmpty() { // setup: we want the real deal here! $this->activeField->setClientOptionsEmpty(false); - + // expected empty $actualValue = $this->activeField->getClientOptions(); - $this->assertTrue(empty($actualValue) === true); + $this->assertTrue(empty($actualValue) === true); } - + public function testGetClientOptionsWithActiveAttributeInScenario() { $this->activeField->setClientOptionsEmpty(false); - + $this->activeField->model->addRule($this->attributeName, 'yiiunit\framework\widgets\TestValidator'); $this->activeField->form->enableClientValidation = false; - + // expected empty $actualValue = $this->activeField->getClientOptions(); - $this->assertTrue(empty($actualValue) === true); - + $this->assertTrue(empty($actualValue) === true); + } - + public function testGetClientOptionsClientValidation() { $this->activeField->setClientOptionsEmpty(false); - + $this->activeField->model->addRule($this->attributeName, 'yiiunit\framework\widgets\TestValidator'); $this->activeField->enableClientValidation = true; $actualValue = $this->activeField->getClientOptions(); @@ -286,7 +286,7 @@ EOD; $this->assertTrue($expectedValidateOnChange === $actualValue['validateOnChange']); $this->assertTrue($expectedValidateOnBlur === $actualValue['validateOnBlur']); $this->assertTrue($expectedValidateOnType === $actualValue['validateOnType']); - $this->assertTrue($expectedValidationDelay === $actualValue['validationDelay']); + $this->assertTrue($expectedValidationDelay === $actualValue['validationDelay']); $this->assertTrue($expectedEnableAjaxValidation === $actualValue['enableAjaxValidation']); } @@ -295,18 +295,18 @@ EOD; $this->activeField->setClientOptionsEmpty(false); $this->activeField->enableAjaxValidation = true; $this->activeField->model->addRule($this->attributeName, 'yiiunit\framework\widgets\TestValidator'); - + foreach($this->activeField->model->validators as $validator) { - $validator->whenClient = "function (attribute, value) { return 'yii2' == 'yii2'; }"; // js + $validator->whenClient = "function (attribute, value) { return 'yii2' == 'yii2'; }"; // js } - + $actualValue = $this->activeField->getClientOptions(); $expectedJsExpression = "function (attribute, value, messages, deferred) {if ((function (attribute, value) " . "{ return 'yii2' == 'yii2'; })(attribute, value)) { return true; }}"; - + $this->assertEquals($expectedJsExpression, $actualValue['validate']->expression); } - + /** * Helper methods */ @@ -320,7 +320,7 @@ EOD; return $view; } - + } /** @@ -329,17 +329,17 @@ EOD; class ActiveFieldExtend extends ActiveField { private $getClientOptionsEmpty; - + public function __construct($getClientOptionsEmpty = true) { $this->getClientOptionsEmpty = $getClientOptionsEmpty; } - + public function setClientOptionsEmpty($value) { $this->getClientOptionsEmpty = (bool) $value; } - + /** * Useful to test other methods from ActiveField, that call ActiveField::getClientOptions() * but it's return value is not relevant for the test being run. @@ -352,12 +352,12 @@ class ActiveFieldExtend extends ActiveField class TestValidator extends \yii\validators\Validator { - + public function clientValidateAttribute($object, $attribute, $view) { return "return true;"; } - + public function setWhenClient($js) { $this->whenClient = $js; diff --git a/tests/unit/framework/widgets/BreadcrumbsTest.php b/tests/unit/framework/widgets/BreadcrumbsTest.php index 730d9e5471..48beee22ee 100644 --- a/tests/unit/framework/widgets/BreadcrumbsTest.php +++ b/tests/unit/framework/widgets/BreadcrumbsTest.php @@ -7,82 +7,82 @@ use yii\widgets\Breadcrumbs; /** * @author Nelson J Morais - * + * * @group widgets */ class BreadcrumbsTest extends \yiiunit\TestCase { private $breadcrumbs; - + public function setUp() { // dirty way to have Request object not throwing exception when running testHomeLinkNull() $_SERVER['SCRIPT_FILENAME'] = "/index.php"; $_SERVER['SCRIPT_NAME'] = "/index.php"; - + $this->mockWebApplication(); $this->breadcrumbs = new Breadcrumbs(); } - + public function testHomeLinkNull() { $this->breadcrumbs->homeLink = null; $this->breadcrumbs->links = ['label' => 'My Home Page', 'url' => 'http://my.example.com/yii2/link/page']; - + $expectedHtml = "
  • Home
  • \n" . "
  • My Home Page
  • \n" . "
  • http://my.example.com/yii2/link/page
  • \n" . "
"; - + ob_start(); $this->breadcrumbs->run(); $actualHtml = ob_get_contents(); ob_end_clean(); - - $this->assertEquals($expectedHtml, $actualHtml); + + $this->assertEquals($expectedHtml, $actualHtml); } - + public function testEmptyLinks() { $this->assertNull($this->breadcrumbs->run()); } - + public function testHomeLinkFalse() { $this->breadcrumbs->homeLink = false; $this->breadcrumbs->links = ['label' => 'My Home Page', 'url' => 'http://my.example.com/yii2/link/page']; - + $expectedHtml = "
  • My Home Page
  • \n" . "
  • http://my.example.com/yii2/link/page
  • \n" . "
"; - + ob_start(); $this->breadcrumbs->run(); $actualHtml = ob_get_contents(); ob_end_clean(); - + $this->assertEquals($expectedHtml, $actualHtml); } - + public function testHomeLink() - { + { $this->breadcrumbs->homeLink = ['label' => 'home-link']; $this->breadcrumbs->links = ['label' => 'My Home Page', 'url' => 'http://my.example.com/yii2/link/page']; - + $expectedHtml = "
  • home-link
  • \n" . "
  • My Home Page
  • \n" . "
  • http://my.example.com/yii2/link/page
  • \n" . "
"; - + ob_start(); $this->breadcrumbs->run(); $actualHtml = ob_get_contents(); ob_end_clean(); - + $this->assertEquals($expectedHtml, $actualHtml); } - + public function testRenderItemException() { $link = ['url' => 'http://localhost/yii2']; @@ -90,48 +90,48 @@ class BreadcrumbsTest extends \yiiunit\TestCase $this->setExpectedException('yii\base\InvalidConfigException'); $method->invoke($this->breadcrumbs, $link, $this->breadcrumbs->itemTemplate); } - + public function testRenderItemLabelOnly() { $link = ['label' => 'My-
Test-Label']; $method = $this->reflectMethod(); - $encodedValue = $method->invoke($this->breadcrumbs, $link, $this->breadcrumbs->itemTemplate); - + $encodedValue = $method->invoke($this->breadcrumbs, $link, $this->breadcrumbs->itemTemplate); + $this->assertEquals("
  • My-<br>Test-Label
  • \n", $encodedValue); - + //without encodeLabels $this->breadcrumbs->encodeLabels = false; $unencodedValue = $method->invoke($this->breadcrumbs, $link, $this->breadcrumbs->itemTemplate); - + $this->assertEquals("
  • My-
    Test-Label
  • \n", $unencodedValue); } - + public function testRenderItemWithLabelAndUrl() { $link = ['label' => 'My-
    Test-Label', 'url' => 'http://localhost/yii2']; $method = $this->reflectMethod(); - $encodedValue = $method->invoke($this->breadcrumbs, $link, $this->breadcrumbs->itemTemplate); - + $encodedValue = $method->invoke($this->breadcrumbs, $link, $this->breadcrumbs->itemTemplate); + $this->assertEquals("
  • My-<br>Test-Label
  • \n", $encodedValue); - + // without encodeLabels - $this->breadcrumbs->encodeLabels = false; - $unencodedValue = $method->invoke($this->breadcrumbs, $link, $this->breadcrumbs->itemTemplate); + $this->breadcrumbs->encodeLabels = false; + $unencodedValue = $method->invoke($this->breadcrumbs, $link, $this->breadcrumbs->itemTemplate); $this->assertEquals("
  • My-
    Test-Label
  • \n", $unencodedValue); } - + public function testRenderItemTemplate() { $link = ['label' => 'My-
    Test-Label', 'url' => 'http://localhost/yii2', 'template' => "{link}\n"]; $method = $this->reflectMethod(); - $encodedValue = $method->invoke($this->breadcrumbs, $link, $this->breadcrumbs->itemTemplate); - + $encodedValue = $method->invoke($this->breadcrumbs, $link, $this->breadcrumbs->itemTemplate); + $this->assertEquals("My-<br>Test-Label\n", $encodedValue); - + // without encodeLabels - $this->breadcrumbs->encodeLabels = false; - $unencodedValue = $method->invoke($this->breadcrumbs, $link, $this->breadcrumbs->itemTemplate); - $this->assertEquals("My-
    Test-Label
    \n", $unencodedValue); + $this->breadcrumbs->encodeLabels = false; + $unencodedValue = $method->invoke($this->breadcrumbs, $link, $this->breadcrumbs->itemTemplate); + $this->assertEquals("My-
    Test-Label
    \n", $unencodedValue); } public function testExtraOptions() @@ -145,7 +145,7 @@ class BreadcrumbsTest extends \yiiunit\TestCase $result = $method->invoke($this->breadcrumbs, $link, $this->breadcrumbs->itemTemplate); $this->assertEquals('
  • demo
  • ' . "\n", $result); } - + /** * Helper methods */ @@ -153,7 +153,7 @@ class BreadcrumbsTest extends \yiiunit\TestCase { $value = new \ReflectionMethod($class, $method); $value->setAccessible(true); - + return $value; } }