func TestAddressAttributeFrontendLabel(t *testing.T) {
	var err error
	cae, err := eav.GetEntityTypeByCode("customer_address")
	if err != nil {
		t.Error(err)
		return
	}
	aIFs, err := cae.AttributeModel.GetByCode("country_ids")
	assert.Error(t, err)
	assert.Nil(t, aIFs)

	attrIF, err := cae.AttributeModel.GetByCode("country_id")
	if err != nil {
		t.Error(err)
		assert.Error(t, err)
	} else {
		var countryID, ok = attrIF.(custattr.Attributer) // type assertion
		if !ok {
			t.Error("failed to convert countryID into custattr.Attributer type")
		}
		assert.True(t, countryID.SortOrder() > 0)
		assert.Equal(t, "Country", countryID.FrontendLabel())
		// t.Logf("\n%#v\n", countryID.SourceModel())
	}

	apc := cae.AttributeModel.MustGet(CustomerAddressAttributePostcode).(custattr.Attributer)
	assert.Equal(t, "Zip/Postal Code", apc.FrontendLabel())
}
Ejemplo n.º 2
0
// TestGetCSEntityType uses the generated CSEntityTypeSlice from the test DB
func TestGetCSEntityType(t *testing.T) {

	tests := []struct {
		id   int64
		code string
		err  bool
	}{
		{1, "customer", false},
		{2, "customer_address", false},
		{3, "catalog_category", false},
		{4, "catalog_product", false},
		{40, "catalog_products", true},
	}

	for _, test := range tests {

		etc, err := eav.GetEntityTypeByID(test.id)
		if test.err {
			assert.Nil(t, etc)
			assert.Error(t, err)
		} else {
			assert.NotNil(t, etc)
			assert.NoError(t, err)
			assert.EqualValues(t, test.id, etc.EntityTypeID)
		}

		etc, err = eav.GetEntityTypeByCode(test.code)
		if test.err {
			assert.Nil(t, etc)
			assert.Error(t, err)
		} else {
			assert.NotNil(t, etc)
			assert.NoError(t, err)
			assert.EqualValues(t, test.id, etc.EntityTypeID)
			assert.EqualValues(t, test.code, etc.EntityTypeCode)
		}

	}

}
// BenchmarkAddressAttributeFrontendLabel	20.000.000	       115 ns/op	       0 B/op	       0 allocs/op
// This is the result for selecting the frontend_label from an attribute assigned to an entity.
// $ac = Mage::getSingleton('eav/config')->getEntityType('customer_address')->getAttributeCollection();
// $ac->addFieldToFilter('attribute_code', ['eq' => 'country_id']);
// $fl = $ac->getFirstItem()->getData('frontend_label');
// PHP 5.5 needs 86600 ns/op (nanosecond) to be fair: with database access but enabled caches with redis and OPcache.
func BenchmarkAddressAttributeFrontendLabel(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		var err error
		cae, err := eav.GetEntityTypeByCode("customer_address")
		if err != nil {
			b.Error(err)
			return
		}

		attrIF, err := cae.AttributeModel.GetByCode("country_id")
		if err != nil {
			b.Error(err)
		} else {
			var countryID, ok = attrIF.(custattr.Attributer) // type assertion
			if !ok {
				b.Error("failed to convert countryID into custattr.Attributer type")
			}
			countryIDFrontendLabel = countryID.FrontendLabel()
		}
	}
}
Ejemplo n.º 4
0
// @todo implement this test also for EntityAttributeCollection
func TestNewAttributeCustomer(t *testing.T) {
	//t.Skip("@todo implement New() attribute functionality")
	for _, et := range []string{"customer", "customer_address", "catalog_product", "catalog_category", "@todo demo"} {
		cu, err := eav.GetEntityTypeByCode(et)
		assert.NoError(t, err)
		ca := cu.AttributeModel.New()

		switch ca.(type) {
		case custattr.Attributer:
			// do here customer attribute stuff
			break
		case catattr.Attributer:
			// do here catalog stuff
			break
		case eav.Attributer:
			// do here default attribute stuff @todo add a sample EAV model
			break
		default:
			t.Errorf("%s Attribute model does not implement interface eav.Attributer and its child interfaces", et)
		}

	}
}