diff --git a/tests/_data/Book.php b/tests/_data/Book.php index 8d58324..96b83cb 100644 --- a/tests/_data/Book.php +++ b/tests/_data/Book.php @@ -12,8 +12,8 @@ * @property string $name * @property integer $year * - * @property integer[] $review_list - * @property integer[] $author_list + * @property integer[] $review_ids + * @property integer[] $author_ids */ class Book extends ActiveRecord { @@ -31,7 +31,7 @@ public static function tableName() public function rules() { return [ - [['author_list', 'review_list'], 'safe'], + [['author_ids', 'review_ids'], 'safe'], [['name', 'year'], 'required'], [['year'], 'integer'], [['name'], 'string', 'max' => 150] @@ -76,8 +76,8 @@ public function behaviors() 'linkerBehavior' => [ 'class' => LinkerBehavior::className(), 'relations' => [ - 'author_list' => ['authors'], - 'review_list' => ['reviews'], + 'author_ids' => ['authors'], + 'review_ids' => ['reviews'], ] ] ]; diff --git a/tests/_data/BookBadFields.php b/tests/_data/BookBadFields.php index 4e9078b..b675fa8 100644 --- a/tests/_data/BookBadFields.php +++ b/tests/_data/BookBadFields.php @@ -23,7 +23,7 @@ public function behaviors() 'author' => [ 'authors', 'fields' => [ - 'list_json' => [ + 'ids_json' => [ 'get' => function ($value) { return Json::encode($value); }, @@ -33,7 +33,7 @@ public function behaviors() ], ], ], - 'author_list' => [ + 'author_ids' => [ 'reviews', 'fields' => [ 'json' => [ diff --git a/tests/_data/BookCustomDefaults.php b/tests/_data/BookCustomDefaults.php index 77fa05b..2d5ec3c 100644 --- a/tests/_data/BookCustomDefaults.php +++ b/tests/_data/BookCustomDefaults.php @@ -17,7 +17,7 @@ class BookCustomDefaults extends Book public function rules() { return [ - [['review_list_none', 'review_list_null', 'review_list_constant', 'review_list_closure'], 'safe'], + [['review_ids_none', 'review_ids_null', 'review_ids_constant', 'review_ids_closure'], 'safe'], [['name', 'year'], 'required'], [['year'], 'integer'], [['name'], 'string', 'max' => 150] @@ -33,22 +33,22 @@ public function behaviors() 'linkerBehavior' => [ 'class' => LinkerBehavior::className(), 'relations' => [ - 'review_list_none' => [ + 'review_ids_none' => [ 'reviews', ], - 'review_list_null' => [ + 'review_ids_null' => [ 'reviews', 'updated' => [ 'defaultValue' => null, ] ], - 'review_list_constant' => [ + 'review_ids_constant' => [ 'reviews', 'updater' => [ 'defaultValue' => 7, ] ], - 'review_list_closure' => [ + 'review_ids_closure' => [ 'reviews', 'updater' => [ 'defaultValue' => function ($updater) { diff --git a/tests/_data/BookJson.php b/tests/_data/BookJson.php index 1436921..a827f3f 100644 --- a/tests/_data/BookJson.php +++ b/tests/_data/BookJson.php @@ -20,7 +20,7 @@ public function behaviors() 'linkerBehavior' => [ 'class' => LinkerBehavior::className(), 'relations' => [ - 'author_list' => [ + 'author_ids' => [ 'authors', 'get' => function ($value) { return Json::encode($value); @@ -29,7 +29,7 @@ public function behaviors() return Json::decode($value); }, ], - 'review_list' => [ + 'review_ids' => [ 'reviews', 'get' => function ($value) { return Json::encode($value); diff --git a/tests/_data/BookJsonFields.php b/tests/_data/BookJsonFields.php index 0311560..0c7c311 100644 --- a/tests/_data/BookJsonFields.php +++ b/tests/_data/BookJsonFields.php @@ -9,10 +9,10 @@ * Class BookJsonFields * @package data * - * @property string $review_list_json - * @property string $review_list_implode - * @property string $author_list_json - * @property string $author_list_implode + * @property string $review_ids_json + * @property string $review_ids_implode + * @property string $author_ids_json + * @property string $author_ids_implode */ class BookJsonFields extends Book { @@ -25,7 +25,7 @@ public function behaviors() 'linkerBehavior' => [ 'class' => LinkerBehavior::className(), 'relations' => [ - 'author_list' => [ + 'author_ids' => [ 'authors', 'fields' => [ 'json' => [ @@ -38,7 +38,7 @@ public function behaviors() ], ], ], - 'review_list' => [ + 'review_ids' => [ 'reviews', 'fields' => [ 'json' => [ diff --git a/tests/unit/BehaviorTest.php b/tests/unit/BehaviorTest.php index a79e231..27fb9c1 100644 --- a/tests/unit/BehaviorTest.php +++ b/tests/unit/BehaviorTest.php @@ -73,7 +73,7 @@ public function testSaveManyToMany() 5, [ 'Book' => [ - 'author_list' => [7, 9, 8] + 'author_ids' => [7, 9, 8] ] ] ); @@ -98,7 +98,7 @@ public function testResetManyToMany() 5, [ 'Book' => [ - 'author_list' => [] + 'author_ids' => [] ] ] ); @@ -117,7 +117,7 @@ public function testSaveOneToMany() 3, [ 'Book' => [ - 'review_list' => [2, 4] + 'review_ids' => [2, 4] ] ] ); @@ -141,7 +141,7 @@ public function testResetOneToMany() 3, [ 'Book' => [ - 'review_list' => [] + 'review_ids' => [] ] ] ); @@ -160,7 +160,7 @@ public function testSaveManyToManyJson() 5, [ 'BookJson' => [ - 'author_list' => '[7, 9, 8]' + 'author_ids' => '[7, 9, 8]' ] ] ); @@ -185,7 +185,7 @@ public function testResetManyToManyJson() 5, [ 'BookJson' => [ - 'author_list' => '[]' + 'author_ids' => '[]' ] ] ); @@ -204,7 +204,7 @@ public function testSaveOneToManyJson() 3, [ 'BookJson' => [ - 'review_list' => '[2, 4]' + 'review_ids' => '[2, 4]' ] ] ); @@ -228,7 +228,7 @@ public function testResetOneToManyJson() 3, [ 'BookJson' => [ - 'review_list' => '[]' + 'review_ids' => '[]' ] ] ); @@ -245,7 +245,7 @@ public function testResetWithDefaultNone() //this model is attached to reviews 1, 2 and 3 - $this->assertTrue($model->load(['BookCustomDefaults' => [ 'review_list_none' => [] ]]), 'Load POST data'); + $this->assertTrue($model->load(['BookCustomDefaults' => ['review_ids_none' => []]]), 'Load POST data'); $this->assertTrue($model->save(), 'Save model'); $result = Yii::$app->db @@ -265,7 +265,7 @@ public function testResetWithDefaultNull() //this model is attached to reviews 1, 2 and 3 - $this->assertTrue($model->load(['BookCustomDefaults' => [ 'review_list_null' => [] ]]), 'Load POST data'); + $this->assertTrue($model->load(['BookCustomDefaults' => ['review_ids_null' => []]]), 'Load POST data'); $this->assertTrue($model->save(), 'Save model'); $result = Yii::$app->db @@ -284,7 +284,7 @@ public function testResetWithDefaultConstant() $this->assertNotEmpty($model, 'Load model'); //this model is attached to reviews 1, 2 and 3 - $this->assertTrue($model->load(['BookCustomDefaults' => [ 'review_list_constant' => [] ]]), 'Load POST data'); + $this->assertTrue($model->load(['BookCustomDefaults' => ['review_ids_constant' => []]]), 'Load POST data'); $this->assertTrue($model->save(), 'Save model'); $result = Yii::$app->db @@ -304,7 +304,7 @@ public function testResetWithDefaultClosure() //this model is attached to reviews 1, 2 and 3 - $this->assertTrue($model->load(['BookCustomDefaults' => [ 'review_list_closure' => [] ]]), 'Load POST data'); + $this->assertTrue($model->load(['BookCustomDefaults' => ['review_ids_closure' => []]]), 'Load POST data'); $this->assertTrue($model->save(), 'Save model'); $result = Yii::$app->db @@ -319,41 +319,41 @@ public function testResetWithDefaultClosure() public function testCustomGettersSetters() { - $reviewList = [1, 2, 4]; - $reviewListJson = Json::encode($reviewList); - $reviewListImplode = implode(',', $reviewList); + $reviewIds = [1, 2, 4]; + $reviewIdsJson = Json::encode($reviewIds); + $reviewIdsImplode = implode(',', $reviewIds); - $authorList = [5, 6]; - $authorListJson = Json::encode($authorList); + $authorIds = [5, 6]; + $authorIdsJson = Json::encode($authorIds); //assign and getters $model = new BookJsonFields; - $model->review_list = $reviewList; - $model->author_list = $authorList; + $model->review_ids = $reviewIds; + $model->author_ids = $authorIds; - $this->assertEquals($model->review_list, $reviewList, 'Direct getter'); - $this->assertEquals($model->author_list, $authorList, 'Direct getter'); + $this->assertEquals($model->review_ids, $reviewIds, 'Direct getter'); + $this->assertEquals($model->author_ids, $authorIds, 'Direct getter'); - $this->assertEquals($model->author_list_json, $authorListJson, 'JSON getter'); - $this->assertEquals($model->review_list_json, $reviewListJson, 'JSON getter'); + $this->assertEquals($model->author_ids_json, $authorIdsJson, 'JSON getter'); + $this->assertEquals($model->review_ids_json, $reviewIdsJson, 'JSON getter'); - $this->assertEquals($model->review_list_implode, $reviewListImplode, 'Implode getter'); + $this->assertEquals($model->review_ids_implode, $reviewIdsImplode, 'Implode getter'); //test json setters $model = new BookJsonFields; - $model->review_list_json = $reviewListJson; - $this->assertEquals($model->review_list, $reviewList, 'JSON setter'); - $model->author_list_json = $authorListJson; - $this->assertEquals($model->author_list, $authorList, 'JSON setter'); + $model->review_ids_json = $reviewIdsJson; + $this->assertEquals($model->review_ids, $reviewIds, 'JSON setter'); + $model->author_ids_json = $authorIdsJson; + $this->assertEquals($model->author_ids, $authorIds, 'JSON setter'); //test implode setter for non-existence where appropriate $model = new BookJsonFields; - $this->assertFalse(isset($model->author_list_implode), 'Non-existence of setter where not declared'); + $this->assertFalse(isset($model->author_ids_implode), 'Non-existence of setter where not declared'); //test implode setter $model = new BookJsonFields; - $model->review_list_implode = $reviewListImplode; - $this->assertEquals($model->review_list, $reviewList, 'Implode setter'); + $model->review_ids_implode = $reviewIdsImplode; + $this->assertEquals($model->review_ids, $reviewIds, 'Implode setter'); } /**