diff --git a/data/class/SC_CustomerList.php b/data/class/SC_CustomerList.php index c9a05de78e..851891e7fb 100644 --- a/data/class/SC_CustomerList.php +++ b/data/class/SC_CustomerList.php @@ -21,13 +21,19 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* [名称] SC_CustomerList - * [概要] 会員検索用クラス +/** + * 会員検索用クラス */ class SC_CustomerList extends SC_SelectSql_Ex { + /** @var array */ public $arrColumnCSV; + /** + * @param array $array 検索パラメータの連想配列 + * @param string $mode 検索モード. 顧客検索の場合は customer + * XXX $mode = 'customer' しか使用していないかも + */ public function __construct($array, $mode = '') { parent::__construct($array); @@ -327,7 +333,9 @@ public function __construct($array, $mode = '') $this->setOrder('customer_id DESC'); } - // 検索用SQL + /** + * 検索用SQL + */ public function getList() { $this->select = 'SELECT customer_id,name01,name02,kana01,kana02,sex,email,email_mobile,tel01,tel02,tel03,pref,status,update_date,mailmaga_flg FROM dtb_customer '; @@ -335,6 +343,9 @@ public function getList() return $this->getSql(2); } + /** + * @deprecated 本体で使用していないため非推奨 + */ public function getListMailMagazine($is_mobile = false) { $colomn = $this->getMailMagazineColumn($is_mobile); @@ -347,7 +358,9 @@ public function getListMailMagazine($is_mobile = false) return $this->getSql(0); } - // 検索総数カウント用SQL + /** + * 検索総数カウント用SQL + */ public function getListCount() { $this->select = 'SELECT COUNT(customer_id) FROM dtb_customer '; @@ -355,7 +368,10 @@ public function getListCount() return $this->getSql(1); } - // CSVダウンロード用SQL + /** + * CSVダウンロード用SQL + * @deprecated 本体で使用していないため非推奨 + */ public function getListCSV($arrColumnCSV) { $this->arrColumnCSV = $arrColumnCSV; diff --git a/tests/class/SC_CustomerListTest.php b/tests/class/SC_CustomerListTest.php new file mode 100644 index 0000000000..7d243e9936 --- /dev/null +++ b/tests/class/SC_CustomerListTest.php @@ -0,0 +1,554 @@ +faker = Faker\Factory::create('ja_JP'); + $this->objGenerator = new FixtureGenerator(); + } + + public function testCreateInstance() + { + $this->setUpCustomers(1); + $this->scenario(); + + $this->assertCount(1, $this->actual); + } + + public function testSearchCustomerId() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->params['search_customer_id'] = $this->customer_ids[0]; + + $this->scenario(); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->verify(); + } + + public function testSearchName01() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_name'] = $this->expected[0]['name01']; + + $this->scenario(); + $this->assertEquals($this->expected[0]['name01'], $this->actual[0]['name01']); + } + + public function testSearchName02() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_name'] = $this->expected[0]['name02']; + + $this->scenario(); + $this->assertEquals($this->expected[0]['name02'], $this->actual[0]['name02']); + } + + public function testSearchKana01() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_kana'] = $this->expected[0]['kana01']; + + $this->scenario(); + $this->assertEquals($this->expected[0]['kana01'], $this->actual[0]['kana01']); + } + + public function testSearchKana02() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_kana'] = $this->expected[0]['kana02']; + + $this->scenario(); + $this->assertEquals($this->expected[0]['kana02'], $this->actual[0]['kana02']); + } + + public function testSearchPref() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_pref'] = $this->expected[0]['pref']; + + $this->scenario(); + $this->assertEquals($this->expected[0]['pref'], $this->actual[0]['pref']); + } + + public function testSearchTel() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_tel'] = $this->expected[0]['tel01'].$this->expected[0]['tel02'].$this->expected[0]['tel03']; + + $this->scenario(); + $this->verify(); + } + + public function testSearchSex() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_sex'] = [$this->expected[0]['sex']]; + + $this->scenario(); + $this->assertEquals($this->expected[0]['sex'], $this->actual[0]['sex']); + } + + public function testSearchJob() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->expected = $this->objQuery->getRow('*', 'dtb_customer', 'customer_id = ?', [$this->customer_ids[0]]); + + $this->params['search_job'] = [$this->expected['job']]; + + $this->scenario(); + // SC_CustomerList::getList() に job が含まれていないので検索し直す + $this->actual = $this->objQuery->getRow('*', 'dtb_customer', 'customer_id = ?', [$this->actual[0]['customer_id']]); + $this->assertEquals($this->expected[0]['pref'], $this->actual[0]['pref']); + } + + public function testSearchJobWithUnknown() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['job' => null], 'customer_id = ?', [$this->customer_ids[0]]); + $this->expected = $this->objQuery->getRow('*', 'dtb_customer', 'customer_id = ?', [$this->customer_ids[0]]); + + $this->params['search_job'] = ['不明']; + + $this->scenario(); + // SC_CustomerList::getList() に job が含まれていないので検索し直す + $this->actual = $this->objQuery->getRow('*', 'dtb_customer', 'customer_id = ?', [$this->actual[0]['customer_id']]); + $this->verify(); + } + + public function testSearchEmail() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_email'] = $this->expected[0]['email'].', '.$this->faker->safeEmail; + + $this->scenario(); + $this->assertEquals($this->expected[0]['email'], $this->actual[0]['email']); + } + + public function testSearchEmailWithExclude() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_email'] = '111'.$this->faker->safeEmail; + $this->params['not_emailinc'] = 1; + + $this->scenario(); + $this->assertCount(3, $this->actual); + } + + public function testSearchEmailMobile() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_email_mobile'] = $this->expected[0]['email_mobile'].', '.$this->faker->safeEmail; + + $this->scenario(); + $this->assertEquals($this->expected[0]['email_mobile'], $this->actual[0]['email_mobile'], 'email_mobile は登録されないため null で一致する'); + } + + public function testSearchEmailMobileWithExclude() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_email'] = '111'.$this->faker->safeEmail; + $this->params['not_email_mobileinc'] = 1; + + $this->scenario(); + $this->assertCount(0, $this->actual, 'email_mobile は登録されないため 0'); + } + + public function testSearchHtmlmail1() + { + $this->objQuery->update('dtb_customer', ['mailmaga_flg' => 3]); + $this->customer_ids = $this->setUpCustomers(3); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_htmlmail'] = '99'; // '全員(メルマガ拒否している会員も含む)' + + $this->scenario(); + $this->assertCount(3, $this->actual, '99 は全員送信対象'); + } + + public function testSearchHtmlmail2() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['mailmaga_flg' => 3]); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_htmlmail'] = ''; // HTML+TEXT + + $this->scenario(); + $this->assertCount(0, $this->actual, 'mailmaga_flg = 3 は受信拒否'); + } + + public function testSearchHtmlmail3() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['mailmaga_flg' => 1], 'customer_id = ?', [$this->customer_ids[0]]); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_htmlmail'] = '1'; // HTML + + $this->scenario(); + $this->assertEquals($this->expected[0]['mailmaga_flg'], $this->actual[0]['mailmaga_flg']); + } + + public function testSearchHtmlmail4() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['mailmaga_flg' => 2], 'customer_id = ?', [$this->customer_ids[0]]); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_htmlmail'] = '2'; // TEXT + + $this->scenario(); + $this->assertEquals($this->expected[0]['mailmaga_flg'], $this->actual[0]['mailmaga_flg']); + } + + public function testSearchMailType1() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', [], '', [], ['email_mobile' => 'email']); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_mail_type'] = 1; // PCメールアドレス + + $this->scenario(); + $this->assertCount(0, $this->actual, 'PCメールアドレスとモバイルメールアドレスが同じ場合は送信されない'); + } + + public function testSearchMailType2() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_mail_type'] = 2; // 携帯メールアドレス + + $this->scenario(); + $this->assertCount(0, $this->actual, 'モバイルメールアドレス未登録者は送信されない'); + } + + public function testSearchMailType3() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['email_mobile' => $this->faker->safeEmail]); + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_mail_type'] = 3; // PCメールアドレス (携帯メールアドレスを登録している会員は除外) + + $this->scenario(); + $this->assertCount(0, $this->actual, 'モバイルメールアドレス登録者は送信されない'); + } + + public function testSearchMailType4() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', [], '', [], ['email_mobile' => 'email']); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_mail_type'] = 4; // PCメールアドレス (携帯メールアドレスを登録している会員は除外) + + $this->scenario(); + $this->assertCount(3, $this->actual, 'email と email_mobile が同じ場合のみ送信される'); + } + + public function testSearchBuyTotalFrom() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['buy_total' => 10000], 'customer_id = ?', [$this->customer_ids[0]]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_buy_total_from'] = 10000; + + $this->scenario(); + $this->verify(); + } + + public function testSearchBuyTotalTo() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['buy_total' => 10001], 'customer_id <> ?', [$this->customer_ids[0]]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_buy_total_to'] = 10000; + + $this->scenario(); + $this->assertCount(1, $this->actual); + } + + public function testSearchBuyTotalFromTo() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['buy_total' => 10001], 'customer_id = ?', [$this->customer_ids[0]]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_buy_total_from'] = 9999; + $this->params['search_buy_total_to'] = 10001; + + $this->scenario(); + $this->assertCount(1, $this->actual); + } + + public function testSearchBuyTimesFrom() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['buy_times' => 10000], 'customer_id = ?', [$this->customer_ids[0]]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_buy_times_from'] = 10000; + + $this->scenario(); + $this->verify(); + } + + public function testSearchBuyTimesTo() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['buy_times' => 10001], 'customer_id <> ?', [$this->customer_ids[0]]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_buy_times_to'] = 10000; + + $this->scenario(); + $this->assertCount(1, $this->actual); + } + + public function testSearchBuyTimesFromTo() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['buy_times' => 10001], 'customer_id = ?', [$this->customer_ids[0]]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_buy_times_from'] = 9999; + $this->params['search_buy_times_to'] = 10001; + + $this->scenario(); + $this->assertCount(1, $this->actual); + } + + public function testSearchBirthFrom() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['birth' => '2030-01-01'], 'customer_id = ?', [$this->customer_ids[0]]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_b_start_year'] = '2030'; + $this->params['search_b_start_month'] = '01'; + $this->params['search_b_start_day'] = '01'; + + $this->scenario(); + $this->verify(); + } + + public function testSearchBirthTo() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['birth' => '1970-01-01'], 'customer_id = ?', [$this->customer_ids[0]]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_b_end_year'] = '1970'; + $this->params['search_b_end_month'] = '01'; + $this->params['search_b_end_day'] = '01'; + + $this->scenario(); + $this->verify(); + } + + public function testSearchBirthFromTo() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['birth' => '1970-01-02'], 'customer_id = ?', [$this->customer_ids[0]]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_b_start_year'] = '1970'; + $this->params['search_b_start_month'] = '01'; + $this->params['search_b_start_day'] = '01'; + $this->params['search_b_end_year'] = '1970'; + $this->params['search_b_end_month'] = '01'; + $this->params['search_b_end_day'] = '02'; + + $this->scenario(); + $this->verify(); + } + + public function testSearchUpdateDateFrom() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['update_date' => '2030-01-01'], 'customer_id = ?', [$this->customer_ids[0]]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_start_year'] = '2030'; + $this->params['search_start_month'] = '01'; + $this->params['search_start_day'] = '01'; + + $this->scenario(); + $this->verify(); + } + + public function testSearchUpdateDateTo() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['update_date' => '1970-01-01'], 'customer_id = ?', [$this->customer_ids[0]]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_end_year'] = '1970'; + $this->params['search_end_month'] = '01'; + $this->params['search_end_day'] = '01'; + + $this->scenario(); + $this->verify(); + } + + public function testSearchUpdateDateFromTo() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['update_date' => '1970-01-02'], 'customer_id = ?', [$this->customer_ids[0]]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_start_year'] = '1970'; + $this->params['search_start_month'] = '01'; + $this->params['search_start_day'] = '01'; + $this->params['search_end_year'] = '1970'; + $this->params['search_end_month'] = '01'; + $this->params['search_end_day'] = '02'; + + $this->scenario(); + $this->verify(); + } + + public function testSearchBuyStartDateFrom() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['last_buy_date' => '2030-01-01'], 'customer_id = ?', [$this->customer_ids[0]]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_buy_start_year'] = '2030'; + $this->params['search_buy_start_month'] = '01'; + $this->params['search_buy_start_day'] = '01'; + + $this->scenario(); + $this->verify(); + } + + public function testSearchBuyStartDateTo() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['last_buy_date' => '1970-01-01'], 'customer_id = ?', [$this->customer_ids[0]]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_buy_end_year'] = '1970'; + $this->params['search_buy_end_month'] = '01'; + $this->params['search_buy_end_day'] = '01'; + + $this->scenario(); + $this->verify(); + } + + public function testSearchBuyStartDateFromTo() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['last_buy_date' => '1970-01-02'], 'customer_id = ?', [$this->customer_ids[0]]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_buy_start_year'] = '1970'; + $this->params['search_buy_start_month'] = '01'; + $this->params['search_buy_start_day'] = '01'; + $this->params['search_buy_end_year'] = '1970'; + $this->params['search_buy_end_month'] = '01'; + $this->params['search_buy_end_day'] = '02'; + + $this->scenario(); + $this->verify(); + } + + public function testSearchBuyProductCode() + { + $this->customer_ids = $this->setUpCustomers(3); + $order_id = $this->objGenerator->createOrder($this->customer_ids[0], [1]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_buy_product_code'] = 'ice-01'; + + $this->scenario(); + $this->verify(); + } + + public function testSearchBuyProductName() + { + $this->customer_ids = $this->setUpCustomers(3); + $order_id = $this->objGenerator->createOrder($this->customer_ids[0], [1]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_buy_product_name'] = 'アイス'; + + $this->scenario(); + $this->verify(); + } + + public function testSearchStatus() + { + $this->customer_ids = $this->setUpCustomers(3); + $this->objQuery->update('dtb_customer', ['status' => '1'], 'customer_id = ?', [$this->customer_ids[0]]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_status'] = [1]; + + $this->scenario(); + $this->verify(); + } + + public function testSearchBuyCategory() + { + $this->customer_ids = $this->setUpCustomers(3); + $order_id = $this->objGenerator->createOrder($this->customer_ids[0], [1]); + + $this->expected = $this->getCustomerList([$this->customer_ids[0]]); + $this->params['search_category_id'] = 5; // アイスクリームのカテゴリ + + $this->scenario(); + $this->verify(); + } + + protected function scenario() + { + $objSelect = new SC_CustomerList_Ex($this->params, 'customer'); + $this->actual = $this->objQuery->getAll($objSelect->getList(), $objSelect->arrVal); + } + + /** + * 比較用の顧客の配列を返す. + * + * @param int[] $customer_ids customer_id の配列 + */ + protected function getCustomerList($customer_ids) + { + return $this->objQuery->getAll('SELECT customer_id,name01,name02,kana01,kana02,sex,email,email_mobile,tel01,tel02,tel03,pref,status,update_date,mailmaga_flg FROM dtb_customer WHERE customer_id IN ('.SC_Utils_Ex::repeatStrWithSeparator('?', count($customer_ids), ',').')', $customer_ids); + } + /** + * @param int $n 生成数 + * @return int[] customer_id の配列 + */ + protected function setUpCustomers($n) + { + $this->objQuery->delete('dtb_customer'); + $result = []; + for ($i = 0; $i < $n; $i++) { + $result[] = $this->objGenerator->createCustomer(); + } + return $result; + } +} diff --git a/tests/class/fixtures/FixtureGenerator.php b/tests/class/fixtures/FixtureGenerator.php index eb221daab1..23ddc21293 100644 --- a/tests/class/fixtures/FixtureGenerator.php +++ b/tests/class/fixtures/FixtureGenerator.php @@ -508,7 +508,7 @@ public function createOrderDetailAsArray($product_class_id, $order_id) 'product_id' => $productsClassValues['product_id'], 'product_class_id' => $product_class_id, 'product_name' => $productsValues['name'], - 'product_code' => $productsValues['product_code'], + 'product_code' => $productsClassValues['product_code'], 'classcategory_name1' => $classcategory_name1, 'classcategory_name2' => $classcategory_name2, 'price' => SC_Helper_TaxRule_Ex::sfCalcIncTax(