Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unitテスト追加 #48

Merged
merged 4 commits into from
Jan 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Model/Behavior/M17nBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ public function saveM17nData(Model $model, $commonFields = null, $associations =
$fieldValue = Hash::get($model->data[$model->alias], $field);

$conditions[$model->alias . '.' . $field . ' !='] = $fieldValue;
if ($fieldValue) {
$conditions[$model->alias . '.' . $field . ''] = null;
}
$commonUpdate[$model->alias][$field] = $fieldValue;
}
}
Expand All @@ -408,6 +411,7 @@ public function saveM17nData(Model $model, $commonFields = null, $associations =
if (! $this->settings[$model->name]['associations']) {
$targetConditions['OR'] = $conditions;
}

$targetDatas = $model->find('all', array(
'recursive' => -1,
'callbacks' => false,
Expand Down
169 changes: 169 additions & 0 deletions Test/Case/Model/Behavior/M17nBehavior/SaveBlockIdTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?php
/**
* M17nBehavior::save()のテスト
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/

App::uses('M17nBehaviorSaveTestBase', 'M17n.TestSuite');
App::uses('TestM17nBSaveBlockIdFixture', 'M17n.Test/Fixture');

/**
* M17nBehavior::save()のテスト
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\M17n\Test\Case\Model\Behavior\M17nBehavior
*/
class M17nBehaviorSaveBlockIdTest extends M17nBehaviorSaveTestBase {

/**
* Fixtures
*
* @var array
*/
public $fixtures = array(
'plugin.m17n.test_m17n_b_save_block_id',
);

/**
* Plugin name
*
* @var string
*/
public $plugin = 'm17n';

/**
* Field key
*
* @var string
*/
public $fieldKey = 'block_id';

/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();

//テストプラグインのロード
NetCommonsCakeTestCase::loadTestPlugin($this, 'M17n', 'TestM17n');
$this->TestModel = ClassRegistry::init('TestM17n.TestM17nBSaveBlockId');
}

/**
* テストデータ
*
* ### 戻り値
* - data 登録データ
*
* @return array テストデータ
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function dataProvider() {
//データ生成
$results = array();

// * 0.コンテンツ新規登録
$index = 0;
$results[$index]['langId'] = '2';
$results[$index]['data'] = array(
'TestM17nBSaveBlockId' => array(
'language_id' => $results[$index]['langId'],
'block_id' => '99',
'content' => 'Test add 1',
),
);
$results[$index]['expected'][0] = Hash::merge($results[$index]['data'], array(
'TestM17nBSaveBlockId' => array(
'is_original_copy' => false,
'is_origin' => true,
'is_translation' => false,
'id' => '5',
),
));

// * 1.「日本語のみ」のデータを日本語で編集
$index = 1;
$results[$index]['langId'] = '2';
$results[$index]['data'] = array(
'TestM17nBSaveBlockId' => array(
'id' => '1',
'language_id' => $results[$index]['langId'],
'block_id' => '1',
'content' => 'Test edit 1',
),
);
$results[$index]['expected'][0] = Hash::merge($results[$index]['data'], array(
'TestM17nBSaveBlockId' => array(
'is_original_copy' => false,
'is_origin' => true,
'is_translation' => false,
'created' => (new TestM17nBSaveBlockIdFixture())->records[0]['created'],
'created_user' => (new TestM17nBSaveBlockIdFixture())->records[0]['created_user'],
),
));

// * 2.「日本語のみ」のデータを英語で編集
$index = 2;
$results[$index]['langId'] = '1';
$results[$index]['data'] = array(
'TestM17nBSaveBlockId' => array(
'id' => '1',
'language_id' => $results[$index]['langId'],
'block_id' => '1',
'content' => 'Test edit 1',
),
);
$results[$index]['expected'][0] = Hash::merge(
array(
'TestM17nBSaveBlockId' => (new TestM17nBSaveBlockIdFixture())->records[0]
),
array(
'TestM17nBSaveBlockId' => array(
'is_translation' => true,
),
)
);
$results[$index]['expected'][1] = Hash::merge($results[$index]['data'], array(
'TestM17nBSaveBlockId' => array(
'is_original_copy' => false,
'is_origin' => false,
'is_translation' => true,
'id' => '5',
),
));

// * 4.「日本語、英語」のデータを日本語で編集
$index = 4;
$results[$index]['langId'] = '2';
$results[$index]['data'] = array(
'TestM17nBSaveBlockId' => array(
'id' => '3',
'language_id' => $results[$index]['langId'],
'block_id' => '3',
'content' => 'Test edit 1',
),
);
$results[$index]['expected'][0] = Hash::merge($results[$index]['data'], array(
'TestM17nBSaveBlockId' => array(
'is_original_copy' => false,
'is_origin' => true,
'is_translation' => true,
'created' => (new TestM17nBSaveBlockIdFixture())->records[2]['created'],
'created_user' => (new TestM17nBSaveBlockIdFixture())->records[2]['created_user'],
),
));
$results[$index]['expected'][1] = array(
'TestM17nBSaveBlockId' => (new TestM17nBSaveBlockIdFixture())->records[3]
);

return $results;
}

}
169 changes: 169 additions & 0 deletions Test/Case/Model/Behavior/M17nBehavior/SaveTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?php
/**
* M17nBehavior::save()のテスト
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/

App::uses('M17nBehaviorSaveTestBase', 'M17n.TestSuite');
App::uses('TestM17nBSaveFixture', 'M17n.Test/Fixture');

/**
* M17nBehavior::save()のテスト
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\M17n\Test\Case\Model\Behavior\M17nBehavior
*/
class M17nBehaviorSaveTest extends M17nBehaviorSaveTestBase {

/**
* Fixtures
*
* @var array
*/
public $fixtures = array(
'plugin.m17n.test_m17n_b_save',
);

/**
* Plugin name
*
* @var string
*/
public $plugin = 'm17n';

/**
* Field key
*
* @var string
*/
public $fieldKey = 'key';

/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();

//テストプラグインのロード
NetCommonsCakeTestCase::loadTestPlugin($this, 'M17n', 'TestM17n');
$this->TestModel = ClassRegistry::init('TestM17n.TestM17nBSave');
}

/**
* テストデータ
*
* ### 戻り値
* - data 登録データ
*
* @return array テストデータ
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function dataProvider() {
//データ生成
$results = array();

// * 0.コンテンツ新規登録
$index = 0;
$results[$index]['langId'] = '2';
$results[$index]['data'] = array(
'TestM17nBSave' => array(
'language_id' => $results[$index]['langId'],
'key' => 'add_key_1',
'content' => 'Test add 1',
),
);
$results[$index]['expected'][0] = Hash::merge($results[$index]['data'], array(
'TestM17nBSave' => array(
'is_original_copy' => false,
'is_origin' => true,
'is_translation' => false,
'id' => '5',
),
));

// * 1.「日本語のみ」のデータを日本語で編集
$index = 1;
$results[$index]['langId'] = '2';
$results[$index]['data'] = array(
'TestM17nBSave' => array(
'id' => '1',
'language_id' => $results[$index]['langId'],
'key' => 'test_1',
'content' => 'Test edit 1',
),
);
$results[$index]['expected'][0] = Hash::merge($results[$index]['data'], array(
'TestM17nBSave' => array(
'is_original_copy' => false,
'is_origin' => true,
'is_translation' => false,
'created' => (new TestM17nBSaveFixture())->records[0]['created'],
'created_user' => (new TestM17nBSaveFixture())->records[0]['created_user'],
),
));

// * 2.「日本語のみ」のデータを英語で編集
$index = 2;
$results[$index]['langId'] = '1';
$results[$index]['data'] = array(
'TestM17nBSave' => array(
'id' => '1',
'language_id' => $results[$index]['langId'],
'key' => 'test_1',
'content' => 'Test edit 1',
),
);
$results[$index]['expected'][0] = Hash::merge(
array(
'TestM17nBSave' => (new TestM17nBSaveFixture())->records[0]
),
array(
'TestM17nBSave' => array(
'is_translation' => true,
),
)
);
$results[$index]['expected'][1] = Hash::merge($results[$index]['data'], array(
'TestM17nBSave' => array(
'is_original_copy' => false,
'is_origin' => false,
'is_translation' => true,
'id' => '5',
),
));

// * 4.「日本語、英語」のデータを日本語で編集
$index = 4;
$results[$index]['langId'] = '2';
$results[$index]['data'] = array(
'TestM17nBSave' => array(
'id' => '3',
'language_id' => $results[$index]['langId'],
'key' => 'test_3',
'content' => 'Test edit 1',
),
);
$results[$index]['expected'][0] = Hash::merge($results[$index]['data'], array(
'TestM17nBSave' => array(
'is_original_copy' => false,
'is_origin' => true,
'is_translation' => true,
'created' => (new TestM17nBSaveFixture())->records[2]['created'],
'created_user' => (new TestM17nBSaveFixture())->records[2]['created_user'],
),
));
$results[$index]['expected'][1] = array(
'TestM17nBSave' => (new TestM17nBSaveFixture())->records[3]
);

return $results;
}

}
Loading